<script>
  function trim_spaces(from_where)
  {
    var temp_string=this;
    document.writeln("in method "+arguments[0]+"<br>");
    if(arguments.length==0)
      from_where="BOTH";
    if(from_where.toUpperCase() == "LEFT" || from_where == "BOTH")
    {
      while(temp_string.left(1)==" ")
      {
	temp_string=temp_string.substring(1);
      }
    }

    if(from_where.toUpperCase()=="RIGHT"||from_where=="BOTH")
    {
      while(temp_string.right(1)==" ")
      {
	temp_string=temp_string.substring(0,temp_string.length-1);
      }
    }
    return temp_string;
  }

  function extract_left(total_chars)
  {
    return this.substring(0,total_chars);
  }

  function extract_right(total_chars)
  {
    return this.substring(this.length-total_chars);
  }

  String.prototype.right=extract_right;
  String.prototype.left=extract_left;
  String.prototype.trim=trim_spaces;

  var my_string="         It was the best of times.       ";
  document.write("----"+my_string.trim("right")+"----");
</script>

